package org.testopencv.image_recognition_3;

import java.util.LinkedList;
import java.util.List;

import org.opencv.core.MatOfDMatch;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.features2d.DMatch;

public class ConsoleView implements MatchingView{

    @Override
    public int showView(MatOfDMatch matches,MatOfKeyPoint srcKP,MatOfKeyPoint dstKP) {
        System.out.println(matches.rows() + " Match Point(s)");

        double maxDist = Double.MIN_VALUE;
        double minDist = Double.MAX_VALUE;

        DMatch[] mats = matches.toArray();
        for(int i = 0;i < mats.length;i++){
            double dist = mats[i].distance;
            if (dist < minDist) {
                minDist = dist;
            }
            if (dist > maxDist) {
                maxDist = dist;
            }
        }
        System.out.println("Min Distance:" + minDist);
        System.out.println("Max Distance:" + maxDist);
        List<DMatch> goodMatch = new LinkedList<>();

        for (int i = 0; i < mats.length; i++) {
            double dist = mats[i].distance;
            //dist < 3*minDist&&
            //goodMatch.add(mats[i]);
            if(dist < 0.12f){
                goodMatch.add(mats[i]);
            }
        }
        System.out.println(goodMatch.size() + " GoodMatch Found");
        int i = 0;
        for(DMatch ma:goodMatch){
            System.out.println("GoodMatch" + "["+i+"]:" + ma.queryIdx + " TO: " + ma.trainIdx + " "+ ma.distance);
            i++;
        }
        return i;
    }

    @Override
    public void setDstPic(String dstPath) {}

    @Override
    public void setSrcPic(String picPath) {}
}